import React, { useContext } from 'react'

const ctx = React.createContext()
export default function comp() {
  return (
    <>
      <ctx.Provider value={{ n: 999 }}>
        <Child />
      </ctx.Provider>
    </>
  )
}

function Child() {
  const data = useContext(ctx)
  return (
    <>
      <div>上下文数据：{data.n}</div>
      {/* 之前的方式获取上下文 */}
      <ctx.Consumer>
        {(data) => {
          return <div>上下文数据：{data.n}</div>
        }}
      </ctx.Consumer>
    </>
  )
}
